# _*_ coding:utf-8 _*_
import os
from celery import Celery
from django.conf import settings

# 设置Django环境变量
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "application.settings")

# 创建Celery实例
app = Celery("scrapper_amazon")

# 使用Django的settings配置Celery
app.config_from_object("django.conf:settings", namespace="CELERY")

# 自动发现任务
app.autodiscover_tasks()

# 配置定时任务
app.conf.beat_schedule = {
    "scrapper-amazon-data-daily": {
        "task": "scrapper.tasks.run_scrapper_command",
        "schedule": "0 1 * * *",  # 每天凌晨1点执行 (cron格式)
    },
}

app.conf.timezone = "Asia/Shanghai"
